home *** CD-ROM | disk | FTP | other *** search
- Path: lerc.nasa.gov!purdue!yuma!steffend
- From: steffend@lamar.colostate.edu (Dave Steffen)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ calling Fortran
- Date: 12 Mar 1996 18:44:15 GMT
- Organization: Colorado State University, Fort Collins, CO 80523
- Message-ID: <4i4glv$3foe@yuma.ACNS.ColoState.EDU>
- References: <4i46vr$njn@filet.nrlssc.navy.mil>
- NNTP-Posting-Host: glitch.physics.colostate.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Gregg A. Jacobs (X4720) (jacobs@proteus) wrote:
- > I want a C++ program to call a subroutine written in fortran.
-
- [snip]
-
- > Then f77 generates an object file with a subroutine name of:
-
- > _foo_
-
- > A C (or C++) routine calling this would be:
-
- > void foo_(float *a);
-
- > main() {
-
- > float a;
- > foo_(&a);
- > }
-
- > The gcc compiler then generates an object file which looks for
- > the name:
- > _foo_
- > This is fine, and the C program calls the fortran subroutine
-
- > However, g++ generates an object file which looks for the name:
- > _foo___FPf
- > The linker can not find this, so the C++ code will not call
- > the fortran subroutine.
-
-
- Right, the C++ compiler will mangle the name of this
- subroutine, just like it mangles the name of every other function
- call. What you need to do is tell g++ "Don't Mangle that Name!" by
- declaring it to have C linkage. Try declaring your routine like this:
-
- extern "C" {
-
- void foo_ (float* a);
- }
-
-
- This tells g++ not to mangle the name, and everything should
- work out. Let me know if it doesn't.
-
- /\
- \/
-
- Dave Steffen No, his mind is not for rent
- Dept. of Physics To any God or Government
- Colorado State University Always hopeful, yet discontent
- steffend@lamar.colostate edu He knows changes aren't permanent-
- But change is...
- "Speak softly...
- ... and carry a black belt!" -Neal Peart / RUSH
- -----------------------------------------------------------------------
-